import cv2 as zhjsw
import numpy as np
filename = r'D:\photo\lena.jpg'
img = zhjsw.imread(filename)
imgblur = zhjsw.blur(img,(5,5))
imgGauss = zhjsw.GaussianBlur(img,(5,5),0)
imgmedian = zhjsw.medianBlur(img,5,0)
'''滤波方式'''

zhjsw.imshow("lena yuanhua",img)
zhjsw.imshow("imgblur",imgblur)
zhjsw.imshow("imgGauss",imgGauss)
zhjsw.imshow("imgmedian",imgmedian)
zhjsw.waitKey()

kernel = np.ones((5,5),np.uint8)
opening = zhjsw.morphologyEx(img,zhjsw.MORPH_OPEN,kernel)
closing = zhjsw.morphologyEx(img,zhjsw.MORPH_CLOSE,kernel)
zhjsw.imshow("closing",closing)
zhjsw.imshow("opening",opening)
zhjsw.waitKey()
'''数学形态学开运算和闭运算'''
kernel = np.ones((5,5),np.uint8)
firstopening = zhjsw.morphologyEx(img,zhjsw.MORPH_OPEN,kernel)
secondclosing = zhjsw.morphologyEx(firstopening,zhjsw.MORPH_CLOSE,kernel)
'''先开后闭'''
zhjsw.imshow("first opening,second closing",secondclosing)
zhjsw.waitKey()
zhjsw.destroyAllWindows()